function resetShareInfo(wxData, wxCallbacks) {
	wx.hideMenuItems({
		menuList: [
			'menuItem:readMode', // 阅读模式
			, 'menuItem:copyUrl' // 原网页
			, 'menuItem:openWithBrowser' // 浏览器打开
			, 'menuItem:openWithQQBrowser' // 浏览器打开
			, 'menuItem:openWithSafari' // 浏览器打开
		],
		success: function (res) {
			//alert('已隐藏“阅读模式”，“复制链接”等按钮');
		},
		fail: function (res) {
			//alert(JSON.stringify(res));
		}
	});

	//获取“分享到朋友圈”按钮点击状态及自定义分享内容接口
	wx.onMenuShareTimeline({
		title: wxData.desc, // 分享标题
		link: wxData.link, // 分享链接
		imgUrl: wxData.imgUrl, // 分享图标
		success: wxCallbacks.success, // 用户确认分享后执行的回调函数
		cancel: wxCallbacks.cancel // 用户取消分享后执行的回调函数
	});

	//获取“分享给朋友”按钮点击状态及自定义分享内容接口
	wx.onMenuShareAppMessage({
		title: wxData.title, // 分享标题
		desc: wxData.desc, // 分享描述
		link: wxData.link, // 分享链接
		imgUrl: wxData.imgUrl, // 分享图标
		type: 'link',// 分享类型,music、video或link，不填默认为link
		dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
		success: wxCallbacks.success, // 用户确认分享后执行的回调函数
		cancel: wxCallbacks.cancel // 用户取消分享后执行的回调函数
	});

	//获取“分享到QQ”按钮点击状态及自定义分享内容接口
	wx.onMenuShareQQ({
		title: wxData.title, // 分享标题
		desc: wxData.desc, // 分享描述
		link: wxData.link, // 分享链接
		imgUrl: wxData.imgUrl, // 分享图标
		success: wxCallbacks.success, // 用户确认分享后执行的回调函数
		cancel: wxCallbacks.cancel // 用户取消分享后执行的回调函数
	});

	//获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口
	wx.onMenuShareWeibo({
		title: wxData.title, // 分享标题
		desc: wxData.desc, // 分享描述
		link: wxData.link, // 分享链接
		imgUrl: wxData.imgUrl, // 分享图标
		success: wxCallbacks.success, // 用户确认分享后执行的回调函数
		cancel: wxCallbacks.cancel // 用户取消分享后执行的回调函数
	});
}

function getScaleImageSize(width, height, b_width, b_height) {
	var rw = width / b_width;
	var rh = height / b_height;
	var rr = width / height;
	if (rw > rh) {
		width = b_width;
		height = width / rr;
	} else {
		height = b_height;
		width = height * rr;
	}
	return { width: width, height: height };
}


function wxrun() {
	//页面加载完后ajax跨域获取签名信息
	var sourceUrl = "http://sc.51zhenzhi.com/Home/GetShareInfo"; //签名地址
	var thisUrl = location.href.split('#')[0]; //本页url
	var sourceData = { url: thisUrl };
	//alert(thisUrl);
	//get
	$.ajax({
		type: "get",
		async: false,
		url: sourceUrl,
		data: sourceData,
		dataType: "json",//跨域操作必须为jsonp数据类型
		success: function (result) {
			//alert(dump(result));
			if (result.Return_code == 0) {
				//通过config接口注入权限验证配置
				wx.config({
					//debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
					appId: result.Return_data.AppId, // 必填，公众号的唯一标识
					timestamp: result.Return_data.TimeStamp, // 必填，生成签名的时间戳
					nonceStr: result.Return_data.NonceStr, // 必填，生成签名的随机串
					signature: result.Return_data.Signature,// 必填，签名
					jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'hideMenuItems'] // 必填，需要使用的JS接口列表
				});
				wx.ready(function () {
					var wxData = {
						"title": '图片编辑器',
						"desc": '简单的图片编辑工具',
						"imgUrl": 'http://game.51zhenzhi.com/app/imageeditor/images/logo.png',
						"link": 'http://game.51zhenzhi.com/app/imageeditor/WXIndex.html'
					};
					var wxCallbacks = {
						success: function () {
							//alert('分享成功'); // 用户确认分享后执行的回调函数
						},
						cancel: function () {
							// 用户取消分享后执行的回调函数
						}
					};
					resetShareInfo(wxData, wxCallbacks);
				});
			} else {
				alert(result.msg);
			}
		},
		error: function () {
			alert('fail');
		}
	});
}

var jsModelPercent = 30;
var resModelPercent = 70;

var js = new Object();
var stage;
var unfixresize = true;
var isGameLoader = null;
var mainlib;

(function () {
	var baseURL = "";
	var isUtf8 = true;
	var arr = ["http://res.wx.qq.com/open/js/jweixin-1.6.0.js?v=1", "js/KISCore.js", "js/KISLib.js", "app/imageeditor/loading.js"];
	var total = arr.length;
	var loaded = 0;
	function onJSFileLoaded(e) {

	}
	for (var i = 0; i < arr.length; i++) {
		var s = document.createElement('script');
		s.src = baseURL + arr[i];
		s.taskIndex = i;
		s.onload = function () {
			loaded++;
			let taskIndex = this.taskIndex;
			window.setLoadPercent(Math.round((loaded / total) * jsModelPercent), taskIndex == 3 ? js.result : null);
			if (total == loaded) {
				if (window.startLoadResource) {
					window.startLoadResource();
				}
			}
			else if (window.setLoadPercent) {
				if (taskIndex == 1) {
					if(!window.stage)
					{
						window.stage = new Stage();
					}
					//wxrun();
				}
			}
		}
		s.onerror = function () {
			loaded++;
			let taskIndex = this.taskIndex;
			window.setLoadPercent(Math.round((loaded / total) * jsModelPercent), taskIndex == 3 ? js.result : null);
			if (total == loaded) {
				if (window.startLoadResource) {
					window.startLoadResource();
				}
			}
		}
		s.onload.bind(s);
		if (isUtf8) {
			s.charset = 'utf-8'
		};
		s.async = false;
		document.body.appendChild(s);
		//document.body.insertBefore(curscript);
	}
})();

(function () {
	var project;
	function start() {
		//删除loading
		if(isGameLoader)
		{
			stage.removeChild(isGameLoader);
		}
		else
		{
			removeDomLoading();
		}
		project = js.result;
		stage.addChild(project);
		if (unfixresize) {
			resizeWindow();
		}
		if(project.startAction){
			project.startAction();
		}
	}

	function configkislib(rman) {

		var mainlib= {images:{manifest:[{src:"app/kisfactory/images/itl.png"},{src:"3pen.svg"},{src:"3circle.svg"},{src:"3rect.svg"},{src:"3garbage.svg"},{src:"3arrow.svg"},{src:"3openfile.svg"},{src:"3download.svg"},{src:"images/spis_3793e12d.png"},{src:"3info.svg"},{src:"3ellipse.svg"}],basePath:"app/imageeditor/images/"}};var mainimages = {};

		if(!mainlib)
		{
			mainlib = {};
		}
		if(!mainlib.properties)
		{
			mainlib.properties = {};
		}
		if(!mainlib.properties.manifest)
		{
			mainlib.properties.manifest =[];
		}
		mainlib.properties.manifest.push({ src: "js/KISGame.js", basePath: "" }, { src: "app/imageeditor/main.js", basePath: "" });


		js.resourceManager.loadExternalLibs([{ lib: mainlib, images: mainimages, imgid: "mainid",isMain:true}]);

		if(rman.getSize() == 0)
		{
			rman.loadExternalLibs([
				{ lib: mainlib, images: {}, imgid: "mainid", isMain: true }
			]);
		}
	}

	function startLoadResource() {
		var rman = new kiscore.ResourceManager();
		js.resourceManager = rman;
		configkislib(rman);

		if (rman.getSize()) {
			rman.addEventListener("complete", handleResComplete);
			rman.addEventListener("progress", handleResProgress);
		} else {
			handleResComplete();
		}
	}
	window.startLoadResource = startLoadResource;

	function handleResProgress(e) {
		setLoadPercent(e.loaded / e.total * resModelPercent + jsModelPercent);
	}
	function handleResComplete(e) {
		if (e) {
			e.currentTarget.removeEventListener("complete", handleResComplete);
			e.currentTarget.removeEventListener("progress", handleResProgress);
		}

		start();
	}

	function onStageMouseDown(e) {
		e.currentTarget.removeETL(e.type, onStageMouseDown);
		let bgSound = new Sound();
		bgSound.play("app/imageeditor/sounds/bg.mp3");
		bgSound.setLoop(true);
	}

	function removeDomLoading() {
		let lgt = document.getElementById("lgt");
		if (lgt) {
			lgt.innerHTML = "";
			let lg = document.getElementById("lg");
			lg.innerHTML = "";
			lg.parentNode.removeChild(lg)
		}
	}

	function setLoadPercent(val, loading) {
		if (loading) {
			isGameLoader = loading;
			removeDomLoading();
			stage = new Stage();
			stage.addChild(loading);
			var s = stage.getStageSize();
			loading.setSize(s.width, s.height);
			stage.addETL(KISU.md, onStageMouseDown)
		}
		else {
			if (isGameLoader) {
				isGameLoader.setValue(val);
			}
			else {
				let lgt = document.getElementById("lgt");
				if (lgt) {
					lgt.innerHTML = "loading..." + Math.round(val*100)/100 + "%"
				}
			}
		}
	}
	window.setLoadPercent = setLoadPercent;

	function resizeWindow() {
		if (stage && project) {
			var s = stage.getStageSize();
			project.setSize(s.width, s.height);
			unfixresize = false;
		} else {
			unfixresize = true;
		}
	}

	function unHandlError(e) {
		//alert(dump(e,"",1));
	}
	//document.addEventListener('deviceready', onDeviceReady, false);
	//document.addEventListener('backbutton', onBackKeyDown, false);
	window.addEventListener("resize", resizeWindow);
	window.addEventListener("error", unHandlError);
}());